// Technology stack: No specific technology stack mentioned

#include <iostream>
#include <string>
#include <unordered_map>

std::unordered_map<std::string, std::string> numeros = {
    {"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"}, {"four", "4"},
    {"five", "5"}, {"six", "6"}, {"seven", "7"}, {"eight", "8"}, {"nine", "9"}
};

int main() {
    std::string input;
    std::cin >> input;
    std::vector<std::string> num;
    for (auto elem : input) {
        num.push_back(elem);
    }
    
    try {
        int numInt = std::stoi(input);
    } catch (const std::invalid_argument& ia) {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }

    int less_prime = numInt;
    int bigger_prime = numInt;

    while (!is_prime(less_prime)) {
        less_prime--;
    }

    while (!is_prime(bigger_prime)) {
        bigger_prime++;
    }

    if (numInt - less_prime < bigger_prime - numInt) {
        std::cout << less_prime << std::endl;
    } else {
        std::cout << bigger_prime << std::endl;
    }

    return 0;
}

bool is_prime(int num) {
    for (int i = 2; i < num; i++) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}